package com.zdkj.subway.rca.enums;

import org.springframework.util.StringUtils;

import java.util.Optional;

/**
 * 银行现金缴款单
 * 数据来源
 * 1：手工录入
 * 2：批量导入
 *
 * @author cooze
 * @version 1.0.0 创建于 2020/10/18
 **/
public enum SW_CK_BANK_CASH_PAYMENT_NOTE_DATA_SOURCE {
    ENTER_MANUALLY("1", "手工录入"),
    BATCH_IMPORT("2", "批量导入");

    SW_CK_BANK_CASH_PAYMENT_NOTE_DATA_SOURCE(String code, String name) {
        this.code = code;
        this.name = name;
    }

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static Optional<SW_CK_BANK_CASH_PAYMENT_NOTE_DATA_SOURCE> toEnum(String code) {
        if (StringUtils.isEmpty(code)) {
            return Optional.empty();
        }
        for (SW_CK_BANK_CASH_PAYMENT_NOTE_DATA_SOURCE E : SW_CK_BANK_CASH_PAYMENT_NOTE_DATA_SOURCE.values()) {
            if (E.getCode().equals(code)) {
                return Optional.of(E);
            }
        }
        return Optional.empty();
    }

    public static boolean isValid(String code) {
        return toEnum(code).isPresent();
    }

    public static boolean isInValid(String code) {
        return !isValid(code);
    }
}
